package com.longcai.piaojia.conn;

import android.util.Log;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/26.
 */
@HttpInlet(Conn.ORDER_VIEW)
public class OrderDetailGet extends BaseAsyGet<OrderDetailGet.OrderDetailEntity> {

    public String order_number;

    public OrderDetailGet(AsyCallBack<OrderDetailEntity> asyCallBack) {
        super(asyCallBack);
    }


    @Override
    protected OrderDetailEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONObject orderDetailObject = object.optJSONObject("data");

            OrderDetailEntity orderDetailEntity = new OrderDetailEntity();

            orderDetailEntity.user_id = orderDetailObject.optString("user_id");
            orderDetailEntity.show_id = orderDetailObject.optString("show_id");
            orderDetailEntity.type = orderDetailObject.optString("type");
            orderDetailEntity.ballot = orderDetailObject.optString("ballot");
            orderDetailEntity.times = orderDetailObject.optString("times");
            orderDetailEntity.performance_time = orderDetailObject.optString("performance_time");
            orderDetailEntity.money = orderDetailObject.optString("money");
            orderDetailEntity.content = orderDetailObject.optString("content");
            orderDetailEntity.seat_id = orderDetailObject.optString("seat_id");
            orderDetailEntity.status = orderDetailObject.optString("status");
            orderDetailEntity.invoice = orderDetailObject.optString("invoice");
            orderDetailEntity.total_money = orderDetailObject.optString("total_money");
            orderDetailEntity.discount_price = orderDetailObject.optString("discount_price");
            orderDetailEntity.postage = orderDetailObject.optString("postage");
            orderDetailEntity.countdown = orderDetailObject.optString("countdown");
            orderDetailEntity.order_number = orderDetailObject.optString("order_number");
            orderDetailEntity.posttime = orderDetailObject.optString("posttime");
            orderDetailEntity.classid = orderDetailObject.optString("classid");
            orderDetailEntity.orderId = orderDetailObject.optString("orderId");
            orderDetailEntity.orderNo = orderDetailObject.optString("orderNo");
            orderDetailEntity.ordertotalAmount = orderDetailObject.optString("ordertotalAmount");
            orderDetailEntity.is_balance = orderDetailObject.optString("is_balance");
            orderDetailEntity.play_id = orderDetailObject.optString("play_id");

            JSONObject orderShowObject = orderDetailObject.optJSONObject("show");

            OrderShowDetail orderShowDetail = new OrderShowDetail();
            orderShowDetail.picurl = Conn.IMAGE_BANNER_URL + orderShowObject.optString("picurl");
            orderShowDetail.title = orderShowObject.optString("title");
            orderShowDetail.posttime = orderShowObject.optString("posttime");
            orderShowDetail.place = orderShowObject.optString("place");
            orderShowDetail.address = orderShowObject.optString("address");


            JSONObject addressObject = orderDetailObject.optJSONObject("address");

            OrderAddress orderAddress = new OrderAddress();
            orderAddress.type = addressObject.optString("type");
            orderAddress.address = addressObject.optString("address");
            orderAddress.name = addressObject.optString("name");
            orderAddress.phone = addressObject.optString("phone");

            String jsonArr = orderDetailObject.optString("coupon");

            JSONArray array = new JSONArray(jsonArr);

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject couponObject = array.optJSONObject(i);

                    OrderCoupon orderCoupon = new OrderCoupon();
                    orderCoupon.id = couponObject.optString("id");
                    orderCoupon.money = couponObject.optString("money");

                    orderDetailEntity.orderCouponList.add(orderCoupon);
                }

            }

            JSONObject objectIntegral = orderDetailObject.optJSONObject("integral");

            OrderIntegral orderIntegral = new OrderIntegral();
            orderIntegral.type = objectIntegral.optString("type");
            orderIntegral.integral = objectIntegral.optString("integral");
            orderIntegral.discount = objectIntegral.optString("discount");


            orderDetailEntity.orderAddress = orderAddress;
            orderDetailEntity.orderIntegral = orderIntegral;
            orderDetailEntity.orderShowDetail = orderShowDetail;

            return orderDetailEntity;


        }


        return null;
    }


    public static class OrderDetailEntity {

        public OrderShowDetail orderShowDetail;
        public OrderAddress orderAddress;
        public OrderIntegral orderIntegral;

        public String user_id, show_id, type, ballot, times, performance_time, money, content, seat_id, status, invoice, total_money, discount_price, postage,countdown, order_number, posttime, classid, orderId, orderNo, ordertotalAmount, is_balance, play_id;

        public List<OrderCoupon> orderCouponList = new ArrayList<>();
    }

    public static class OrderShowDetail {

        public String title = "";
        public String picurl = "";
        public String posttime = "";
        public String place = "";
        public String address = "";

    }

    public static class OrderAddress {

        public String type = "";
        public String name = "";
        public String address = "";
        public String phone = "";

    }

    public static class OrderCoupon {

        public String id = "";
        public String money = "";

    }

    public static class OrderIntegral {

        public String type = "";
        public String integral = "";
        public String discount = "";

    }




}
